/*
 * $Id: lnxapi.h,v 1.3 2005-09-02 10:22:40 bacon Exp $
 */

#ifndef _XP_BAS_LNXAPI_H_
#define _XP_BAS_LNXAPI_H_

#ifdef __linux

#include <xp/types.h>
#include <xp/macros.h>
#include <linux/types.h>
#include <linux/limits.h>
#include <linux/wait.h>
#include <linux/stat.h>

typedef __kernel_uid_t xp_uid_t;
typedef __kernel_gid_t xp_gid_t;
typedef __kernel_pid_t xp_pid_t;

typedef __kernel_mode_t xp_mode_t;
typedef __kernel_off_t xp_off_t;

/* stat */
typedef struct stat xp_stat_t;

/* maximum number of characters in a path name excluding nul */
#define XP_PATH_MAX (PATH_MAX - 1)

/* "option" values for xp_wait. can be ORed with each other. */
#define XP_WNOHANG    WNOHANG
#define XP_WUNTRACED  WUNTRACED

#define XP_WEXITCODE(status)   (((status) & 0xFF00) >> 8)
#define XP_WTERMSIG(status)    ((status) & 0x7F)
#define XP_WSTOPSIG(status)    (XP_WEXITCODE(status))
#define XP_WIFEXITED(status)   (XP_WTERMSIG(status) == 0)
#define XP_WIFSIGNALED(status) (!XP_WIFSTOPPED(status) && !XP_WIFEXITED(status))	
#define XP_WIFSTOPPED(status)  (((status) & 0xFF) == 0x7F)
#define XP_WCOREDUMP(status)   ((status) & 0x80)

#ifdef __cplusplus
extern "C" {
#endif

xp_uid_t xp_getuid (void);
xp_uid_t xp_geteuid (void);
xp_gid_t xp_getgid (void);
xp_gid_t xp_getegid (void);

xp_pid_t xp_setsid (void);
xp_pid_t xp_getpid (void);
xp_pid_t xp_getppid (void);

int xp_setpgid (xp_pid_t pid, xp_pid_t pgid);
xp_pid_t xp_getpgid (xp_pid_t pid);
int xp_setpgrp (void);
xp_pid_t xp_getpgrp (void);

xp_pid_t xp_fork (void);
xp_pid_t xp_wait (xp_pid_t pid, int *status, int options);

int xp_pipe (int pfd[2]);

xp_mode_t xp_umask (xp_mode_t mode);

/* handled io */
int xp_open (const xp_char_t* path, int flag, ...);
int xp_close (int handle);
xp_ssize_t xp_read (int handle, void* buf, xp_size_t sz);
xp_ssize_t xp_write (int handle, const void* data, xp_size_t sz);
xp_off_t xp_hseek (int handle, xp_off_t offset, int whence);
int xp_hstat (int handle, xp_stat_t* buf);

#ifdef __cplusplus
}
#endif

#endif

#endif
